package com.ttg.common.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author ZQ
 * @version 1.0
 * @Description
 * @date 2020/12/17 14:31
 */
public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
    private String forMate = "yyyy-MM-dd HH:mm:ss";
    public LocalDateTimeSerializer(){
    }
    public LocalDateTimeSerializer(String f){
        this.forMate = f;
    }
    @Override
    public void serialize(LocalDateTime value, JsonGenerator generator, SerializerProvider serializers) throws IOException {
        generator.writeString(value.format(DateTimeFormatter.ofPattern(forMate)));
    }
}
